# -*- coding:utf-8 -*-

import sys
from common.import_pyside import *

class DemoItemWidgets(QMainWindow):
    def __init__(self, parent=None):
        super(DemoItemWidgets, self).__init__(parent)

        # 设置窗口标题
        self.setWindowTitle('实战PyQt5: MV框架 项视图部演示')
        # 设置窗口大小
        self.resize(640, 360)

        self.initUi()

    def initUi(self):
        splitter = QSplitter(Qt.Horizontal)

        # 列表部件
        listWidget = QListWidget(splitter)
        # 方式一，直接添加
        listWidget.addItem('Sycamore')
        # 方式二使用listWidget构建一个项
        QListWidgetItem('Chestnut', listWidget)
        # 方式三，创建一个项，再插入
        newItem = QListWidgetItem()
        newItem.setText('Mahogany')
        newItem.setToolTip('this is a tool tip')
        newItem.setStatusTip('this is a status tip')
        newItem.setWhatsThis('this is a whats tis text')
        listWidget.insertItem(listWidget.count(), newItem)

        # 树形部件
        treeWidget = QTreeWidget(splitter)
        # 设置列数
        treeWidget.setColumnCount(2)
        # 设置头信息
        treeWidget.setHeaderLabels(['Subject', 'Default'])
        # 添加项
        cities = QTreeWidgetItem(treeWidget)
        cities.setText(0, 'Cities')
        osloItem = QTreeWidgetItem(cities)
        osloItem.setText(0, 'Oslo')
        osloItem.setText(1, 'Yes')
        plants = QTreeWidgetItem(treeWidget, cities)
        plants.setText(0, 'Plants')

        # 表格部件
        tableWidget = QTableWidget(12, 3, splitter)
        # 在每个项里填充合适的值
        for row in range(12):
            for column in range(3):
                newItem = QTableWidgetItem(str(pow(row, (column + 1))))
                tableWidget.setItem(row, column, newItem)
        # 设置第一列的表头信息
        valuesHeaderItem = QTableWidgetItem('values')
        tableWidget.setHorizontalHeaderItem(0, valuesHeaderItem)

        splitter.addWidget(listWidget)
        splitter.addWidget(treeWidget)
        splitter.addWidget(tableWidget)
        self.setCentralWidget(splitter)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = DemoItemWidgets()
    window.show()
    sys.exit(app.exec())